package com.lin.setting.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.lin.setting.dao.SysUserDao;
import com.lin.setting.entity.SysUser;
import com.lin.setting.service.SysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @作者: 林江
 * @创建时间: 2024/5/3
 * @功能:
 */
@Service
public class SysUserServiceImpl implements SysUserService {
    @Resource
    SysUserDao sysUserDao;

    @Override
    public List<SysUser> getInfo() {
        return sysUserDao.selectList(null);
    }

    @Override
    public void updateSysUser(SysUser user) {
        LambdaUpdateWrapper<SysUser> wrapper = new UpdateWrapper<SysUser>()
                .lambda()
                .set(Objects.isNull(user.getUsername()), SysUser::getUsername, user.getUsername())
                .set(Objects.isNull(user.getPassword()), SysUser::getPassword, user.getPassword())
                .eq(SysUser::getId, user.getId());

        sysUserDao.update(wrapper);

    }
}
